home *** CD-ROM | disk | FTP | other *** search
/ C++ für Kids / C++ for kids.iso / Buch / Rund2a.cpp < prev    next >
C/C++ Source or Header  |  1998-12-27  |  3KB  |  91 lines

  1. //---------------------------------------------------------------------------
  2. #include <vcl\vcl.h>
  3. #pragma hdrstop
  4.  
  5. #include "Rund2a.h"
  6. //---------------------------------------------------------------------------
  7. #pragma resource "*.dfm"
  8.  
  9. class TKreis
  10. {
  11. public:
  12.   int x, y, Dicke;
  13.   void Erscheinen (void);
  14.   void Bewegen (void);
  15.   void Verschwinden (void);
  16.   float Flaeche (void);
  17.   float Umfang (void);
  18.   TKreis (int xx, int yy, int dd);
  19. };
  20.  
  21. TKreis *Kreis;
  22. TForm1 *Form1;
  23. //---------------------------------------------------------------------------
  24. TKreis::TKreis(int xx, int yy, int dd)
  25. {
  26.   x = xx; y = yy; Dicke = dd;
  27. }
  28. //---------------------------------------------------------------------------
  29. void TKreis::Erscheinen (void)
  30. {
  31.   Form1->Canvas->Ellipse (x, y, x+Dicke, y+Dicke);
  32. }
  33. //---------------------------------------------------------------------------
  34. void TKreis::Bewegen (void)
  35. {
  36.   TRect Quelle, Ziel;
  37.   for (int i=x-5; i<Form1->ClientWidth-Dicke-x-5; i++)
  38.   {
  39.     Quelle = Rect(i,   y-5, i+Dicke+5, y+Dicke+5);
  40.     Ziel   = Rect(i+1, y-5, i+Dicke+6, y+Dicke+5);
  41.     Form1->Canvas->CopyRect(Ziel, Form1->Canvas, Quelle);
  42.     // Bremse, abhΣngig vom Prozessortakt!
  43.     for (int j=0; j<1000000; j++) ;
  44.   }
  45. }
  46. //---------------------------------------------------------------------------
  47. void TKreis::Verschwinden (void)
  48. {
  49.   Form1->Refresh ();
  50. }
  51. //---------------------------------------------------------------------------
  52. float TKreis::Flaeche (void)
  53. {
  54.   const pi=3.141592654;
  55.   return pi*(Dicke/2)*(Dicke/2);
  56. }
  57. //---------------------------------------------------------------------------
  58. float TKreis::Umfang (void)
  59. {
  60.   const pi=3.141592654;
  61.   return pi*Dicke;
  62. }
  63. //---------------------------------------------------------------------------
  64. __fastcall TForm1::TForm1(TComponent* Owner)
  65.     : TForm(Owner)
  66. {
  67. }
  68. //---------------------------------------------------------------------------
  69. void __fastcall TForm1::Button1Click(TObject *Sender)
  70. {
  71.   Kreis->Erscheinen ();
  72.   Canvas->TextOut (65,90, "FlΣche = " + String(Kreis->Flaeche()));
  73.   Canvas->TextOut (65,110, "Umfang = " + String(Kreis->Umfang()));
  74. }
  75. //---------------------------------------------------------------------------
  76. void __fastcall TForm1::Button2Click(TObject *Sender)
  77. {
  78.   Kreis->Bewegen ();
  79. }
  80. //---------------------------------------------------------------------------
  81. void __fastcall TForm1::Button3Click(TObject *Sender)
  82. {
  83.   Kreis->Verschwinden ();
  84. }
  85. //---------------------------------------------------------------------------
  86. void __fastcall TForm1::FormCreate(TObject *Sender)
  87. {
  88.   Kreis = new TKreis (30, 30, 150);
  89. }
  90. //---------------------------------------------------------------------------
  91.